//
//  CSXMLNode.m
//  cactus-xml
//
//  Created by Yury Nikalayuk on 11.06.10.
//  Copyright 2011 CactusSoft. All rights reserved.
//

#import "CSXMLNode.h"


@implementation CSXMLNode

@synthesize value;
@synthesize attributes;
@synthesize children;
@synthesize name;

-(id) initWithName:(NSString *)_name
{
	if(self = [super init])
	{
		name = [_name retain];
		value = [[NSString alloc] init];
		attributes = [[NSMutableDictionary alloc] init];
		children = [[NSMutableArray alloc] init];
	}
	return self;
}

-(void) dealloc
{
	[name release];
	[value release];
	[attributes release];
	[children release];
	
	[super dealloc];
}

-(CSXMLNode *) child:(NSString *)childName
{
	for(CSXMLNode *child in children)
	{
		if([child.name compare:childName] == NSOrderedSame) {
			return child;
		}
	}
	
	return nil;
}

-(NSString *) attribute:(NSString *)attributeName
{
	NSString *attributeValue = [attributes objectForKey:attributeName];
	if(attributeValue == nil)
		return [NSString string];
	else
		return attributeValue;
}

@end
